package com.tianxiao.faas.application.aop;

import org.springframework.core.NamedThreadLocal;

public class AuthenticationContextHolder {
    private static final ThreadLocal<AuthenticationContext> authenticationContextHolder =
            new NamedThreadLocal<>("authentication context");

    public static void setContext(AuthenticationContext context) {
        if (context == null) {
            authenticationContextHolder.remove();
        } else {
            authenticationContextHolder.set(context);
        }
    }

    public static void remove() {
        authenticationContextHolder.remove();
    }

    public static AuthenticationContext currentContext() {
        return authenticationContextHolder.get();
    }
}
